package com.article.service.Impl;

import com.article.entity.dto.ArticleTypeDao;
import com.article.entity.dto.SearchArticleTypeDao;
import com.article.entity.pojo.ArticleType;
import com.article.entity.vo.ArticleTypeVo;
import com.article.mapper.ArtcleTypeMapper;
import com.article.service.ArtcleTypeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ArtcleTypeServiceImpl extends ServiceImpl<ArtcleTypeMapper, ArticleType> implements ArtcleTypeService {

    @Autowired
    private ArtcleTypeMapper artcleTypeMapper;

    @Override
    public List<ArticleType> getArticleType(int page, int size) {
        int pageStart = (page - 1) * size;
        return artcleTypeMapper.getArticleType(pageStart, size);
    }

    @Override
    public int addArticleType(ArticleTypeDao articleTypeDao) {
        ArticleType article = artcleTypeMapper.getArticle(articleTypeDao.getTypeName2(), articleTypeDao.getTypeName());
        if (article != null) {
            return 0;
        }

        return artcleTypeMapper.addArticleType(articleTypeDao);
    }

    @Override
    public int deleteArticleType(Integer id) {
        return artcleTypeMapper.deleteById(id);
    }

    @Override
    public int deleteArticleTypes(List<Integer> ids) {
        return artcleTypeMapper.deleteBatchIds(ids);
    }

    @Override
    public int updateArticleType(ArticleTypeDao articleTypeDao) {
        return artcleTypeMapper.updateArticleTypeById(articleTypeDao);

    }

    @Override
    public List<ArticleTypeVo> searchArticleType(SearchArticleTypeDao searchArticleTypeDao) {
        return artcleTypeMapper.searchArticleType(searchArticleTypeDao);
    }

    @Override
    public int selectArticleTypeNumber() {
        return artcleTypeMapper.selectArticleTypeNumber();
    }
}
